package com.comac.tasks.manager.app.common.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * 排序规则枚举类
 */
public enum OrderRuleEnum {
    /**
     *
     */
    ASC("asc", "升序"),

    /**
     *
     */
    DESC("desc", "降序");

    /**
     * 编码
     */
    @Getter
    private String code;

    /**
     * 描述
     */
    @Getter
    private String desc;

    public static String getType(String code) {
        for (OrderRuleEnum c : OrderRuleEnum.values()) {
            if (code.equals(c.getCode())) {
                return c.getDesc();
            }
        }
        return null;
    }

    OrderRuleEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static OrderRuleEnum match(String no) {
        if (no == null) {
            return null;
        }
        OrderRuleEnum[] enums = OrderRuleEnum.values();
        return Arrays.stream(enums).filter(item -> item.code.equals(no)).findAny().orElse(null);
    }
}
